package com.jinlejia.bbs.logic;

import android.content.Context;

import com.alibaba.fastjson.JSONObject;
import com.jinlejia.bbs.http.utils.BBSConfig;
import com.jinlejia.bbs.http.utils.HttpCallBack;

import static com.jinlejia.bbs.http.utils.HttpUtils.JsonParse;
import static com.jinlejia.bbs.http.utils.HttpUtils.httpCallBack;
import static com.jinlejia.bbs.http.utils.HttpUtils.httpCallForm;

/**
 * @author 王进 on 2019/3/31.
 */
//忽略邀请
public class IgnoreInviterecordLogic {
    private Context context;

    public IgnoreInviterecordLogic(Context context) {
        this.context = context;
    }
    private volatile boolean isExecute = false;
    public void execute(int id, final LogicCallBack callBack) {
        if (isExecute)return;
        isExecute = true;
        JSONObject json = new JSONObject();
        json.put("id", id);
        httpCallForm(BBSConfig.updateInviterecordState, json)
                .execute(httpCallBack(context, new HttpCallBack() {
                    @Override
                    public void onError(Exception e) {
                        callBack.onResult(false);
                        isExecute = false;
                    }

                    @Override
                    public void onResponse(JsonParse parse) {
                        isExecute = false;
                        boolean result = parse.parse(Boolean.class);
                        callBack.onResult(result);
                    }

                    @Override
                    public void onNoResponse(int code) {
                        isExecute = false;
                        callBack.onResult(false);
                    }
                }));
    }

    public interface LogicCallBack {
        void onResult(boolean result);
    }
}
